package org.example.myleet.rosalind.tran;

import org.example.myleet.rosalind.utils.FastaReader;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
//        solution.calculateTransitionTransversionsRatio(FastaReader.parseFastaInput(">Rosalind_0209\n" +
//                "GCAACGCACAACGAAAACCCTTAGGGACTGGATTATTTCGTGATCGTTGTAGTTATTGGA\n" +
//                "AGTACGGGCATCAACCCAGTT\n").get(0).getSequence(), FastaReader.parseFastaInput(">Rosalind_2200\n" +
//                "TTATCTGACAAAGAAAGCCGTCAACGGCTGGATAATTTCGCGATCGTGCTGGTTACTGGC\n" +
//                "GGTACGAGTGTTCCTTTGGGT\n").get(0).getSequence());
        solution.calculateTransitionTransversionsRatio(FastaReader.parseFastaInput(">Rosalind_3932\n" +
                "TAATGCGAAACTAGTAGTAACCAAAGCATATATCGTGCTCAATCGCTAGTTTATAAGTTT\n" +
                "ACACCGTCTGGAGTCTTCTGTAACACCACAACCATAATTCGCAGAACGCCCTGGTTGGTG\n" +
                "CCCCTCTGTGTACAGGCCCTACTTGGGCGCTAGGGTCCGGCTTAGGAGCTCAACTGCGGA\n" +
                "GCACCCGTTTGACCCTGACACCGTGGGCTCAGTCTTCACGACGCCTTATTTCGCAGGTTA\n" +
                "GGATCCACCGTGGAGAGGTTCGAACCGGTCTGTATCCCATTTGCGTCGACTCCTCGACGA\n" +
                "TTTGCTCTTGCGTGTGGCGGTGACCAGCCGTGTGGGGTAATGACCGCCCGATCCGACGGG\n" +
                "TCGATACACCACGTCCCCTATTCAGGGTTTAACAATGTAGGAGCACTTCATGCGCGTTGT\n" +
                "GCCGTCCGATATACAAACATTGTGCAGGGTCCGCCTTCTCAGCTGGCCCAACCAAGATTG\n" +
                "CCAACGCGGGGTTAACGCCCTATAATTACTCTAAAATCGTATTATGGAAACACGTACGCA\n" +
                "AATTAAAGGTTGTTGCGCGAACCCTGCCCGCCGGAGAACCGTCCCCGTCGTACAGAGGGC\n" +
                "AGGATATGTACACCACCAGCGGTGGTTGCGTCGAATAACAACGATCCATTGGTTCATGAC\n" +
                "GGCCCAAGGCGCAGATGGAAGTTCGGATCCTCATGGCAGATAGGGTCGTCGGGGTATTAC\n" +
                "CTTGCAAGACCTGGCGGGCGACGCAGTGTAGATATAGTCCTTTAACGCACCTAAGCAATC\n" +
                "AATACGTAGCTCGATAACGTCATCTCGGAGTGTTTCTGAACGTTAACGAATTATTCTTAG\n" +
                "ATGTTCCAGCTGATGTGTGGTAATTCATATCAGCATCTATATACCATACCGTTCCTCCTT\n" +
                "TCTGTGTGTACGACTGATACCGCTAAGACCATGCCGACATACAGCACCA\n").get(0).getSequence(), FastaReader.parseFastaInput(">Rosalind_0153\n" +
                "TAATGTGAAACTATTAGGAACTTCAGCATTGATCGTTCCTAGTCTTTAATCTTTGAGTTT\n" +
                "AGACTGTTTGAAGTCTTCTCCAGCTTCACAACATAATTTCGCACAGCGTCCCCGTTGTTG\n" +
                "CCCGTCCATGAGTAGGCGCTACTTGCGCACCAGAGTTCGGGTTGGAAGCGCGACTACGGA\n" +
                "GCACCCGTCTGACCTCGACATTACTAGCTCAGTCCTCTTGACGCCTGATCTCGCTGTTTA\n" +
                "GGATCGATCGTACAGAGATCTCAACCGGTCTATATCCCATTCGCATCGACTCGTTGACGA\n" +
                "TTGGCTGCCGTCTGTGTCTGCAACCAGCCGTGTGCGGTGATGTTCATCGGACCTGACGGG\n" +
                "CCGATACGCTATGATCCCTGTTCAAGGTTAACCAAAATAGATGCCCTTCATACGTGTTGC\n" +
                "GCTGATTGGTACATTAACATTGCGCAGAGCCCACTTTCGCAGCTGGCCCACTAAAGATCG\n" +
                "TCGATAAGAGGTTAATGCCTTGTAGTTACCCTAATACCGTGAAGAGGAAACATGTACCCG\n" +
                "AGTTGAAGGTCGCCGAGCAAACCTTGCCCGCTGGATAAGCTTCCCCGGCGTACAGAGAGT\n" +
                "GAGACATGCACACGATCAACCATTGTCGCGTCGAAAATCAACAATGCATTGGACCATGAC\n" +
                "GGTGCAGAGCGCAAATGAAAACCCGGATCCTTATGGCAGAAAGGGTTGTTAGGGTATTAC\n" +
                "CTAGTGAGACCTGACGGGCGACACAGTATAGGCATAACCCCTCACCGCATCTAGGCAATC\n" +
                "AGTATGTAACTCAACATTGTCATCTCGAGGTGTTTCTGTTTAATAACCGGTCACTATCAG\n" +
                "ATGTTTCAGTCGACGTGTGAAAGCTTATGCCAAGCTCTATCAGCCATATCGTTCCACCGA\n" +
                "ACAGTGTGCGTGACAGATACGATTAAGGTCATGCCGATATTCAGCCTGA\n").get(0).getSequence());
    }

    public void calculateTransitionTransversionsRatio(String seq1, String seq2) {
        int transition = 0, transversion = 0;
        for (int i = 0; i < seq1.length(); ++i) {
            char c1 = seq1.charAt(i), c2 = seq2.charAt(i);
            if (c1 == c2) {
                continue;
            }
            if (c1 == 'A' || c1 == 'G') {
                if (c2 == 'C' || c2 == 'T') {
                    ++transversion;
                } else {
                    ++transition;
                }
            } else if (c1 == 'C' || c1 == 'T') {
                if (c2 == 'A' || c2 == 'G') {
                    ++transversion;
                } else {
                    ++transition;
                }
            }
        }
        BigDecimal transitionVsTransversionRation = BigDecimal.valueOf(transition).divide(BigDecimal.valueOf(transversion), 11, RoundingMode.HALF_UP);
        System.out.println(transitionVsTransversionRation.toPlainString());
    }
}
